<?php
class Server {
  public static function delete_obj($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    $orm->delete('pb_ecom_product', $req);
    if (isset($req->__pg) && isset($req->__o) && isset($req->__q)) {
      $res = $orm->get('pb_ecom_product', $req->__o, $req->__q, $req->__pg, SIZE, NULL);
      echo json_encode($res);
    }
  }
  
  public static function get_objs($orm, $sys, $inst, $is_iframe) {
    $req = json_decode(Utils::get_param('req', '[]'));
    $opts = new stdClass();
    if (isset($req->search->type) && isset($req->search->phrase)) {
      if ($req->search->type == 1) {
        $opts->cd = 't.status = :v1';
        $opts->cdv = array(':v1' => 1);
      } else if ($req->search->type == 2) {
        $opts->cd = 't.status = :v1';
        $opts->cdv = array(':v1' => 0);
      } else if ($req->search->type == 3) {
        $opts->cd = 't.alert__ = :v1 AND t.status = :v2';
        $opts->cdv = array(':v1' => 1, ':v2' => 1);
      }
      
      if ($req->search->type != 0) {
        $opts->cd .= ' AND ';
      }
      
      $opts->cd .=  '(t.name LIKE :v3)';
      $opts->cdv[":v3"] = '%' . $req->search->phrase . '%';
    }
    $res = $orm->get('pb_ecom_product', $req->o, $req->q, $req->pg, SIZE, $opts);
    echo json_encode($res);
  }
}
?>